home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13775 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: grimsel.zurich.ibm.com!usenet
  2. From: wgk@zurich.ibm.com (Keith Whittingham)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: reversing a string
  5. Date: 10 Apr 1996 07:36:10 GMT
  6. Organization: IBM Research, ZRH
  7. Message-ID: <4kfoda$eue@grimsel.zurich.ibm.com>
  8. References: <4k6cjl$j8f@central.server.swt.edu> <4kb1s7$6eu@ibm32.perftech.com> <829058514snz@genesis.demon.co.uk> <4ke0b9$rk5@grimsel.zurich.ibm.com> <DpM3Kz.6t4@iquest.net>
  9. Reply-To: wgk@zurich.ibm.com
  10. NNTP-Posting-Host: pine.zurich.ibm.com
  11. X-Newsreader: IBM NewsReader/2 v1.00
  12.  
  13. In <DpM3Kz.6t4@iquest.net>, dlmiller@iquest.net (Doug Miller) writes:
  14. >wgk@zurich.ibm.com (Keith Whittingham) wrote:
  15. >>Ole!  (pronounced Spanishly but written 'olleh')
  16. >>
  17. >>Well here's a starter - no second variable but two recursive functions.
  18. >>Hopefully that can be reduced to one if my project can spare the time.
  19. >>(Note to manager: don't worry, just joking).
  20. >>
  21. >>#include <stdio.h>
  22. >>
  23. >>void RecRev2(char *s)
  24. >>  {
  25. >>  if(s[1])
  26. >>    {
  27. >>    if(s[2])
  28. >>      {
  29. >>      RecRev2(&s[1]);
  30. >>      }
  31. >>    s[0] ^= s[1]; s[1] ^= s[0]; s[0] ^= s[1];
  32. >>    }
  33. >>  }
  34. >>
  35. >>void RecRev1(char *s)
  36. >>  {
  37. >>  if(s && *s)
  38. >>    {
  39. >>    RecRev2(s);
  40. >>    RecRev1(&s[1]);
  41. >>    }
  42. >>  }
  43. >>
  44. >>int main(int argc, char *argv)
  45. >>  {
  46. >>  char *s = "Hello";
  47. >>  RecRev1(s);
  48. >>  puts(s);
  49. >>  return 0;
  50. >>  }
  51. >>
  52. >This breaks if the string begins and ends with the same character.
  53.  
  54. What are you talking about?!
  55.  
  56. Keith
  57.  
  58.  
  59.